Grrr Posted May 28, 2016 Share Posted May 28, 2016 Hi again guys, Today I've came up with an idea for "creating" mtext, before inserting it in the drawing. I use similar lisp for a single-line mtext (just type and pick insertion point), since I hate the standard command with defining the mtext box first and then type. However this one differs as it allows the user to type every row, and when its done to insert it. A list is constructed, where each item represents a new row, but I'm having issues with the "\P" addition infront of each item, and I can't make the "multiline" mtext: ; Attempt to type MTEXT: ; Construct list of strings, when done add "\P" between items, then entmake mtext with content of that list ; In user-speaking language: type rows for the mtext until done, then insert the mtext (defun c:test ( / ans mtxt-list pt1) (setq cont T) (setq mtxt-list (list)) (initget "Finish") ; how to loop to type mtexts and pick points? (loop the loop) (while cont ; loop to type rows (setq ans (getstring t "\nType a row for mtext or [Finish] : ")) ; ask for content of the row (cond ( (or (and (= ans "Finish") mtxt-list ) (and (= ans "FINISH") mtxt-list ) (and (= ans "F") mtxt-list ) (and (= ans "f") mtxt-list ) ) ; check if the list is not nil (setq cont F) ; stop loop for typing rows (setq pt1 (getpoint "\nSpecify insertion point for the mtext:")) (M-Text pt1 (substr (vl-princ-to-string (reverse mtxt-list)) 2 (- (strlen (vl-princ-to-string mtxt-list)) 2)) ) ; removed first and last syntax ) (t (setq mtxt-list (cons (strcat (substr "x\P" 2) ans) mtxt-list)) ; how to add "\P" infornt each item? (print (reverse mtxt-list))(princ (strcat ", " (itoa (length mtxt-list)) " rows.")) ); t );cond );while (princ) );defun ; LM (defun M-Text (pt str) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 str) (cons 71 5) ) ) ) The next (not so big) problem that I have is that I'm trying to while loop this entire thing, so after the mtext is entmake'd the user would be prompt for typing a row for a new mtext. (and so on.. type rows for mtext, pick point.. and so on). I've commented parts of the code for you to understand easier what I'm doing there. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 28, 2016 Share Posted May 28, 2016 Some thoughts to chew. (defun c:test (/ go lst ans p) (setq go t lst "") (while (and go (setq ans (getstring t "\nType a row for mtext or [Enter to Finish] :"))) (cond ((and (/= ans "") (eq (type ans) 'str)) (setq lst (strcat lst ans "\\P")) ) ((and (eq ans "") (/= lst "") (setq p (getpoint "\nSpecify insertion point for the mtext:")) ) (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans p 1 0)) (cons 1 lst) '(71 . 5) )) (setq go nil)) ((= ans "") (setq go nil)) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted May 28, 2016 Author Share Posted May 28, 2016 I did a quick try and seems to work, later I'll analyse it more carefully and I'll try to figure out how to loop this loop. At first glance I see that you skipped my substr and vl-princ-to-string functions, so new information would be provided for me. Thank you again, Tharwat! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 28, 2016 Share Posted May 28, 2016 Good luck. Quote Link to comment Share on other sites More sharing options...
Grrr Posted May 28, 2016 Author Share Posted May 28, 2016 Just did it, looped the whole thing: (defun c:test (/ go2 go lst ans p) (setq go2 T) (while go2 (setq go T) (setq lst "") (while (and go (setq ans (getstring t "\nType a row for mtext or [Enter to Finish] :"))) (cond ( (and (/= ans "") (eq (type ans) 'str)) (setq lst (strcat lst ans "\\P")) ) ( (and (eq ans "") (/= lst "") (setq p (getpoint "\nSpecify insertion point for the mtext:"))) (if (and (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans p 1 0)) (cons 1 lst) '(71 . 5) ) ) (setq go nil) ) (setq go2 T) ) ) ( (= ans "") (setq go nil) (setq go2 F) ) ); cond ); sub-while ); main while (princ) );defun There might be some illogical conditions, but everything works fine. I'm impressed how you figured to use a fake list, and just construct a very long string while separating the inputs with "\\P" ! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 28, 2016 Share Posted May 28, 2016 Grr there was a post to add colour, font style etc both Lee and I posted may be useful in future. Found it http://www.cadtutor.net/forum/showthread.php?92585-HELP-Change-only-the-colour-of-numbers-in-an-mtext&highlight=Mtext Quote Link to comment Share on other sites More sharing options...
Grrr Posted May 29, 2016 Author Share Posted May 29, 2016 Thats an interesting thread, BIGAL I usually don't format my text/mtext objects, but I'll see if I can learn something new from these codes. The solutions (codes) posted in there seem to become more and more complex, and there are always these additional modification requests (for personal usage). Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 29, 2016 Share Posted May 29, 2016 (and (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity")'(100 . "AcDbMText")(cons 10 (trans p 1 0))(cons 1 lst)'(71 . 5))) (setq go nil) ) The above and function will NOT return true since one of the expressions is equal to nil. (setq go2 F) I think it is better to set a variable to nil than set it to a null symbol as in your case. Quote Link to comment Share on other sites More sharing options...
Grrr Posted May 29, 2016 Author Share Posted May 29, 2016 Did corrections on the code, upon Tharwats comment: (defun c:test (/ go2 go lst ans p) (setq go2 T) (while go2 (setq go T) (setq lst "") (while (and go (setq ans (getstring t "\nType a row for mtext or [Enter to Finish] :"))) (cond ( (and (/= ans "") (eq (type ans) 'str)) (setq lst (strcat lst ans "\\P")) ) ( (and (eq ans "") (/= lst "") (setq p (getpoint "\nSpecify insertion point for the mtext:"))) (if (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans p 1 0)) (cons 1 lst) '(71 . 5) ) ) (progn (setq go nil) (setq go2 T) ) ) ) ( (= ans "") (setq go nil) (setq go2 nil) ) ); cond ); sub-while ); main while (princ) );defun Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 29, 2016 Share Posted May 29, 2016 (progn (setq go nil) (setq go2 T) ) [/quote] A bit less coding if you are interested. [code] (setq go nil go2 t) Quote Link to comment Share on other sites More sharing options...
Grrr Posted May 29, 2016 Author Share Posted May 29, 2016 A bit less coding if you are interested. (setq go nil go2 t) Nice found! I'm not used with this way of writing the code (writing the setq function just like progn), not sure whys that - maybe its easier to trace (if the code has problem) by myself. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.